package com.coincalf.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.coincalf.dto.NoticeDTO;
import com.coincalf.dto.NoticeDTOMapper;
import com.coincalf.entity.EntrustOrder;
import com.coincalf.entity.Notice;
import com.coincalf.framework.enums.BaseStatus;
import com.coincalf.framework.enums.OrderStatus;
import com.coincalf.mapper.NoticeMapper;
import com.coincalf.service.NoticeService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 系统资讯公告信息 服务实现类
 * </p>
 *
 * @author qiang
 * @since 2018-05-12
 */
@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements NoticeService {

    /**
     * 分页查询公告信息
     *
     * @param page
     * @return
     */
    @Override
    public Page<NoticeDTO> queryNoticeList(Page<Notice> page) {
        EntityWrapper<Notice> wrapper = new EntityWrapper<>();
        wrapper.eq("status", BaseStatus.EFFECTIVE.getCode())
                .orderBy("created", false);
        Page<Notice> noticePage = super.selectPage(page, wrapper);
        List<Notice> records = noticePage.getRecords();
        List<NoticeDTO> notices = NoticeDTOMapper.INSTANCE.from(records);
        Page<NoticeDTO> noticeList = new Page<>();
        noticeList.setRecords(notices)
                .setTotal(noticePage.getTotal())
                .setSize(noticePage.getSize())
                .setCurrent(noticePage.getCurrent());
        return noticeList;
    }

}
